package me.cjj.android.assignment.model;

public class LinearQuestion implements IQuestion {

    private int k;
    private int d;

    public LinearQuestion(int k, int d) {
        this.k = k;
        this.d = d;
    }

    public String getQuestionText() {
        String kText = Utils.toQuestionText(k, "x", true);
        String dText = Utils.toQuestionText(d, "", false);
        return "\\(" + kText + dText + "=0\\)";
    }

    public int getAnswerCount() {
        return 1;
    }

    public String getAnswerText() {
        return getAnswer() + "";
    }

    public boolean judge(float... answers) {
        float correct = getAnswer();
        return (Math.round(correct * 100) / ((float) 100)) == answers[0];
    }

    private float getAnswer() {
        return -((float) d) / ((float) k);
    }

}
